package org.nanotek.persistence.jpa.base.brainz.artist;

import java.util.List;

import org.nanotek.base.artist.Artist;
import org.nanotek.base.person.name.NamePart;
import org.nanotek.persistence.DAOException;
import org.nanotek.persistence.jpa.base.person.PersonDAO;
/**
 * 
 * @author josecanovamauger
 *
 * @param <T>
 */
public class ArtistDAO <T extends Artist> extends PersonDAO<Artist>{

	public ArtistDAO() {
		this.baseClass =  Artist.class;
	}
	
	public Artist findArtist(Long id) throws DAOException
	{ 
		return super.find(id);
	}
	
	public void persistArtist(T artist) throws DAOException
	{ 
		super.persist(artist);
	}
	
	public Boolean containsArtist(T artist) 
	{ 
		return super.contains(artist);
	}
	
	
	public List<?> findArtistByNameValue(String name)
	{ 
		String jpql = "Select Artist a from Artist a inner join NamePerson np where np inner join NamePart npa where npa.value like :value ";
		return entityManager.createQuery(jpql).setParameter("value", name).getResultList();
	}

	public List<?> findArtistByNamePart(NamePart namePart)
	{ 
		String jpql = "Select Artist a from Artist a inner join NamePerson np where np inner join NamePart npa where npa  = :value ";
		return entityManager.createQuery(jpql).setParameter("value", namePart).getResultList();
	}

//	@SuppressWarnings({"unused" , "rawtypes"})
//	public Artist findArtistByName(String name) 
//	{ 
//		
//		CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
//		CriteriaQuery<Artist> criteriaQuery = criteriaBuilder.createQuery(Artist.class);
//		
//		Metamodel metaModel = entityManager.getMetamodel();
//		CriteriaQuery<NamePerson> namePersonQuery = criteriaBuilder.createQuery(NamePerson.class); 
//		
//		Root <?> personRoot = getRoot(getBaseClass());
//        Join<?, NamePerson> neighborCountry = personRoot.join("name");
//		Root<NamePerson> nameRoot = getRoot(NamePerson.class);
//
//		EntityType<NamePerson> personEt = getEntityType(namePersonQuery, NamePerson.class);
////		Attribute<?, ?> cs = personEt.getAttribute("value");
//
//		Metamodel model = entityManager.getMetamodel();
//		ManagedType personType = model.managedType(Person.class);
//		Attribute<Person,Set<?>> nameAttribute = personType.getSet("name");
//		
////		addressJoin.alias("a");
//		
//		 
//		  // Navigation Paths:
////		  Path<String> countryName = country.get("name");
////		  Path<City> capital = country.get("capital");
////		  Path<String> captialName = capital.get("name");
//		  
////		nameStringQuery.where(nameRoot.get())
////		
////		CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(getBaseClass());
////		Root<Artist> artistRoot = criteriaQuery.from(Artist.class);
//		
//		return null;
//	}
	
}
